package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
public class NursingPlanContorller {
    @Autowired
    private NursingPlanService nursingPlanService;

    //查询全部护理计划
    @GetMapping
    public ResponseResult findAll(){
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.findAll();
        return ResponseResult.success(nursingPlanVos);
    }
    //新增护理计划
    @PostMapping
    public ResponseResult add(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return ResponseResult.success();
    }
    //条件分页查询
    @GetMapping("/search")
    public ResponseResult page(
            String name,
            Integer pageNum,
            Integer pageSize,
            Integer status
    ){
        PageResponse<NursingPlanVo> nursingPlanVos = nursingPlanService.page(name, pageNum, pageSize, status);
        return ResponseResult.success(nursingPlanVos);
    }
    //根据id查询
    @GetMapping("/{id}")
    public ResponseResult findById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.findById(id);
        return ResponseResult.success(nursingPlanVo);
    }
    //修改项目
    @PutMapping("/{id}")
    public ResponseResult update(NursingPlanDto nursingPlanDto,@PathVariable Long id){
        nursingPlanService.update(nursingPlanDto);
        return ResponseResult.success();
    }
    //删除项目
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingPlanService.deleteById(id);
        return ResponseResult.success();
    }
    //启动禁用
    @PutMapping("/{id}/status/{status}")
    public ResponseResult status(@PathVariable Long id,@PathVariable Integer status){
        nursingPlanService.status(id,status);
        return ResponseResult.success();
    }

}
